﻿
Public Class Round
    Private myTricks As List(Of Trick)
    Private myDealer As Player
    Private myGroup As List(Of Player)
    Private myTrump As Suite
    Private myWinner As Team
    Private isLoner As Boolean
    Private myPointsAwarded As Integer
    Private myCaller As Player
    Private myDeck As List(Of Card)

    Public ReadOnly Property Winner As Team
        Get
            Return myWinner
        End Get
    End Property

    Public ReadOnly Property PointsAwarded As Integer
        Get
            Return myPointsAwarded
        End Get
    End Property

    Public Sub New(ByVal dealer As Player, ByVal group As List(Of Player))
        myDealer = dealer
        myGroup = group
        myTricks = New List(Of Trick)
        myWinner = Nothing
        myPointsAwarded = 0
        myTrump = Nothing
        myCaller = Nothing
        isLoner = False
        myDeck = GetRandomDeck()
    End Sub

    ''' <summary>
    ''' Plays a round and sets winner and points earned
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Start()
        Dim points As Integer = 0
        Dim trick As Trick = Nothing
        Dim team1wins As Integer = 0
        Dim team2wins As Integer = 0
        'TODO
        'Deal out hands

        'TODO
        'get caller from GUI/database
        myTrump = Suite.Hearts
        'TODO
        'get caller from GUI/database
        myCaller = myGroup(2)
        'TODO
        'get loner from GUI/database
        isLoner = False

        For trickCount As Integer = 1 To MAX_TRICKS
            trick = New Trick(myDealer, myGroup)
            trick.Start()
            'sum up team wins
            Select Case trick.Winner.Team
                Case Team.One
                    team1wins += 1
                Case Team.Two
                    team2wins += 1
            End Select
            'TODO
            'update the scoreboard to show tricks taken

            'Store trick info
            myTricks.Add(trick)
        Next

        'pick winner
        If team1wins > 2 Then
            myWinner = Team.One
        Else
            myWinner = Team.Two
        End If
        'calculate points to award
        Select Case myCaller.Team
            Case Team.One
                Select Case team1wins
                    Case 1, 2
                        myPointsAwarded = 2
                    Case 3, 4
                        myPointsAwarded = 1
                    Case 5
                        myPointsAwarded = 2
                        If isLoner Then myPointsAwarded = 4
                End Select
            Case Team.Two
                Select Case team2wins
                    Case 1, 2
                        myPointsAwarded = 2
                    Case 3, 4
                        myPointsAwarded = 1
                    Case 5
                        myPointsAwarded = 2
                        If isLoner Then myPointsAwarded = 4
                End Select
        End Select
    End Sub


End Class
